package com.ymatou.iapi.counter.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.counter.parameter.SetNaturalBean;
import com.ymatou.iapi.counter.service.SetNaturalCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 设置计数器 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SetNatural {
	private static SetNaturalCall setNaturalCall;
	private static SetNaturalBean setNaturalBean;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置计数器");
	}

	@Before
	public void caseUp() {
		setNaturalBean = new SetNaturalBean();
		setNaturalCall = new SetNaturalCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setNaturalCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SetNatural_001() {
		Logger.start(true,"设置计数器成功");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			// new CounterCallService().setGroup("Test","c1", TargetId, 1, 1);
			// 参数
			setNaturalBean.setAppId("Test");
			setNaturalBean.setAction(1);
			setNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd'T'HH:mm:ss");
			setNaturalBean.setDataTime(DataTime);
			setNaturalBean.setTargetId(TargetId);
			int i = 2;
			setNaturalBean.setValue(i);
			setNaturalCall.setData(setNaturalBean);
			setNaturalCall.callService();
			Logger.verifyEquals(200, setNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, setNaturalCall.getMsg(), "验证Msg");
			Logger.verifyEquals(2, setNaturalCall.getData(), "计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SetNatural_002() {
		Logger.start(true,"设置计数器(减少)成功");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			// new CounterCallService().setGroup("Test","c1", TargetId, 1, 1);
			// 参数
			setNaturalBean.setAppId("Test");
			setNaturalBean.setAction(2);
			setNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd'T'HH:mm:ss");
			setNaturalBean.setDataTime(DataTime);
			setNaturalBean.setTargetId(TargetId);
			int i = 2;
			setNaturalBean.setValue(i);
			setNaturalCall.setData(setNaturalBean);
			setNaturalCall.callService();
			Logger.verifyEquals(200, setNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, setNaturalCall.getMsg(), "验证Msg");
			Logger.verifyEquals(-2, setNaturalCall.getData(), "验证计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SetNatural_003() {
		Logger.start(true,"设置计数器(设置)成功");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			// new CounterCallService().setGroup("Test","c1", TargetId, 1, 1);
			// 参数
			setNaturalBean.setAppId("Test");
			setNaturalBean.setAction(3);
			setNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd'T'HH:mm:ss");
			setNaturalBean.setDataTime(DataTime);
			setNaturalBean.setTargetId(TargetId);
			int i = 2;
			setNaturalBean.setValue(i);
			setNaturalCall.setData(setNaturalBean);
			setNaturalCall.callService();
			Logger.verifyEquals(200, setNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, setNaturalCall.getMsg(), "验证Msg");
			Logger.verifyEquals(2, setNaturalCall.getData(), "验证计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SetNatural_004() {
		Logger.start(true,"设置计数器(清零)成功");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			// new CounterCallService().setGroup("Test","c1", TargetId, 1, 1);
			// 参数
			setNaturalBean.setAppId("Test");
			setNaturalBean.setAction(4);
			setNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd'T'HH:mm:ss");
			setNaturalBean.setDataTime(DataTime);
			setNaturalBean.setTargetId(TargetId);
			int i = 2;
			setNaturalBean.setValue(i);
			setNaturalCall.setData(setNaturalBean);
			setNaturalCall.callService();
			Logger.verifyEquals(200, setNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, setNaturalCall.getMsg(), "验证Msg");
			Logger.verifyEquals(0, setNaturalCall.getData(), "验证计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}